package com.ygo.feihua;

import android.content.*;
import android.view.*;
import android.widget.*;
import cn.bmob.v3.datatype.*;
import java.util.*;
import android.view.View.*;
import java.io.*;
import android.os.*;
import android.app.*;
import com.ygo.feihua.util.*;

public class Xlitem extends BaseAdapter
{
	List<Map<String,Object>> data;
	Context context;
	private TextView xl_name;
	private Button xl_yy,xl_sc;
	DialogUtils du;
	
	
	public Xlitem(Context context, List<Map<String,Object>> data)
	{
		this.context = context;
		this.data=data;
		du=DialogUtils.getdx(context);
		
	}
    
	@Override
	public int getCount()
	{
		return data.size();
	}

	@Override
	public Object getItem(int position)
	{
		return data.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent)
	{
		View view = LayoutInflater.from(context).inflate(
			R.layout.xlitem, null);
			
		final Gongju gj=Gongju.getdx(context);
			
		xl_name=(TextView) view.findViewById(R.id.xl_name);
		xl_yy=(Button) view.findViewById(R.id.xl_yy);
		xl_sc=(Button) view.findViewById(R.id.xl_sc);
		xl_name.setText((String)data.get(position).get("name"));
		final String path=(String) data.get(position).get("path");
		
		
		xl_sc.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{				
				View[] v=du.dialogt(true,path,"确定要删除这个主题吗？");
				Button b1,b2;
				
				b1=(Button) v[0];
				b2=(Button) v[1];
				
				b1.setText("取消");
				b2.setText("确定");
					b1.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								du.dis();
								// TODO: Implement this method
							}
						});
					b2.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View p1)
							{
								if(FileUtil.delFile(path)){
									data.remove(position);
									notifyDataSetChanged();

									gj.show("删除成功");
								}else{
									gj.show("删除失败");
								}
								
								
								// TODO: Implement this method
							}
						});
					
					
					// TODO: Implement this method
				}
			});
		xl_yy.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					gj.yyzt(path);
					// TODO: Implement this method
				}
			});
		return view;
	}
}
